package com.laoyao.service;

import com.jfinal.aop.Duang;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class CollectService {
	public static final CollectService me = Duang.duang(CollectService.class);
	private static CollectService dao = Duang.duang(CollectService.class);
	
	/**
	 * 判断用户是否收藏过该视频
	 * @param userId
	 * @param videoId
	 * @return
	 */
	public boolean isExist(String userId,String videoId){
		String sql = "select * from v_collect where userId=? and videoId=?";
		return Db.findFirst(sql,userId,videoId)!=null;
	}
	/**
	 * 视频被收藏数量
	 * @param videoId
	 * @return
	 */
	public Long collectNum(String videoId){
		String sql = "select count(*) num from v_collect where videoId=?";
		return Db.findFirst(sql,videoId).getLong("num");
	}
	
	/**
	 * 视频收藏列表
	 * @param pageNumber
	 * @param pageSize
	 * @param id
	 * @return
	 */
	public Page<Record> list(Integer pageNumber,Integer pageSize,String id){
		String sql = "select a.*,b.userName  from v_video a,v_user b,v_collect c where a.userId=b.id and c.videoId=a.id and c.userId=?"
				+ " order by time desc";
		return Db.paginate(pageNumber, pageSize, sql,id);
	}
}
